package com.kdtech.analyse.video;
import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 * http://www.cditv.cn/ 成都电视台
 * @author 小聂 
 */
public class CditvVideoAnalyse implements AnalyseNews{

	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				"http://www.cditv.cn/show-[0-9]*-[0-9]{4,}-[0-9]*.html",
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta video = new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}		
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();
		if(!isDetailPage(url)){
		}
		
		video.setUrl(url);		
		String title = null;
		Long date = null;
		String desc = null;
		Document doc = Jsoup.parse(htmltxt);
		title = doc.select("h1").text();
		
		if(StringUtils.isBlank(title)){
			title=doc.select("title").text();
		}
		date = DateUtils.matchDate(doc.select(".show-info").text());
		if(StringUtils.isBlank(desc)){
			desc=doc.select(".des,.desc").text();
		}
		if(title == null || title.trim().length() == 0 || date == null){
		}
		video.setDate(date);
		video.setContent(doc.select("div.description").text());
		video.setTitle(title);
		video.setType(2);
		video.setContent(desc);
		return video;
	}

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}
	
	
	
}
